﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Entities;
using System.Collections.Generic;
using ThoiTrang.Business;

public partial class UserControls_Footer : System.Web.UI.UserControl
{
    private int _groupId;
    public int GroupId
    {
        get { return _groupId; }
        set { _groupId = value; }
    }

    private int _SubId;
    public int SubId
    {
        get { return _SubId; }
        set { _SubId = value; }
    }

    private int _MainId;
    public int MainId
    {
        get { return _MainId; }
        set { _MainId = value; }
    }
        
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData(); 
    }

    protected void LoadData()
    {
        try
        {
            a_SEO_Content seoContent = (a_SEO_Content)Cache["Geta_SEO_ContentListByCatMainAndCatSub_" + MainId.ToString() + SubId.ToString()]; 
            if (seoContent == null)
            {
                seoContent = a_SEO_ContentService.Geta_SEO_ContentListByCatMainAndCatSub(MainId, SubId);
                Cache.Insert("Geta_SEO_ContentListByCatMainAndCatSub_" + MainId.ToString() + SubId.ToString(), seoContent, null, DateTime.Now.AddHours(FOConstants.ExpireCache), System.Web.Caching.Cache.NoSlidingExpiration);
            }
            if (seoContent == null) return;
            lbH1.InnerHtml = seoContent.H1.Replace("\"&strYearPrevious&\"", (DateTime.Now.Year - 1).ToString()).Replace("\"&strYear&\"", DateTime.Now.Year.ToString());
            lbH2.InnerHtml = seoContent.H2.Replace("\"&strYearPrevious&\"", (DateTime.Now.Year - 1).ToString()).Replace("\"&strYear&\"", DateTime.Now.Year.ToString());
            lbH4.InnerHtml = seoContent.Paragraph.Replace("\"&strYearPrevious&\"", (DateTime.Now.Year - 1).ToString()).Replace("\"&strYear&\"", DateTime.Now.Year.ToString());
            FOConstants.SetPadding(seoContent.Paragraph);
            //Response.Write("lazy[" + seoContent.Paragraph.Length.ToString());
        }
        catch (Exception ex)
        {
            FOConstants.SetPadding("");
        }
    }

    protected string LoadFooterItems()
    {
        string codeStr = string.Empty;
        try
        {
            List<a_CatMain> catMains = (List<a_CatMain>)Cache["Geta_CatMainListByGroup_" + GroupId.ToString()];
            if (catMains == null)
            {
                catMains = a_CatMainService.Geta_CatMainListByGroup(GroupId);
                Cache.Insert("Geta_CatMainListByGroup_" + GroupId.ToString(), catMains, null, DateTime.Now.AddHours(FOConstants.ExpireCache), System.Web.Caching.Cache.NoSlidingExpiration);
            }
            foreach (a_CatMain catMain in catMains)
            {
                List<a_CatSub> catSubs = (List<a_CatSub>)Cache["Geta_CatSubListByCatMain_" + catMain.CatID.ToString()];
                if (catSubs == null)
                {
                    catSubs = a_CatSubService.Geta_CatSubListByCatMain(catMain.CatID);
                    Cache.Insert("Geta_CatSubListByCatMain_" + catMain.CatID.ToString(), catSubs, null, DateTime.Now.AddHours(FOConstants.ExpireCache), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                for (int i = 0; i < catSubs.Count; i++)
                {
                    string link = ResolveUrl(TTHelper.GetDetailLink(catMain, catSubs[i]));
                    codeStr += String.Format("<a href=\"{0}\">{1}</a>\n                    ", link, catSubs[i].Name);
                }
            }
            return codeStr;
        }
        catch (Exception ex)
        {
        }
        return string.Empty;
    }
}
